<template>
	<view class="content">
		<mescroll-body ref="mescrollRef" :bottombar="false" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="u-m-20">
				<block v-for="(item,index) in goodsList" :key="index">
					<view class="flex flex-column u-p-20 u-m-b-20 bg-white rounded-10 shadow">
						<view class="flex justify-between u-p-b-15 u-border-bottom">
							<text>{{item.order_no}}</text>
							<text class="text-danger">{{item.type==0?'仅换货':item.type==1?'退款':'退货退款'}}</text>
						</view>
						<text class="flex u-p-y-10">{{item.store_name}}</text>
						<block v-for="(item1,indey) in item.goodsinfo" :key="item1.id">
							<order-item-list-good :item="item1" :index="index" @toOrderDetail="toOrderDetail"></order-item-list-good>
						</block>
						<view class="flex flex-column align-end">
							<view class="flex align-center justify-end text-center u-p-t-20">
								<dy-button backgroundColor="#fff" color="#333" borderColor="#C2C5C8" disabled>{{item.status}}</dy-button>
								<dy-button class="u-m-l-30" width="140rpx" backgroundColor="#fff" color="#333" borderColor="#C2C5C8" @click="delOrder(item.id)">删除记录</dy-button>
								<dy-button class="u-m-l-30" width="140rpx" @click="toDetail(item.order_no, item.id, item.goods_id)">查看详情</dy-button>
							</view>
						</view>
					</view>
				</block>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import { OrderCenterApi } from '@/api/serves.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				goodsList: [],
			}
		},
		onLoad() {
			uni.$on('itemClick', ()=> {
				this.mescroll.resetUpScroll()
			})
		},
		onUnload() {
			uni.$off('itemClick')
		},
		methods: {
			// 上拉加载
			upCallback(page) {
				OrderCenterApi.get_history({page: page.num}).then(res=> {
					console.log('售后订单列表', res);
					if(res.code == 1){
						let result = res.data.data
						if(page.num == 1) this.goodsList = []; //如果是第一页需手动制空列表
						this.goodsList = this.goodsList.concat(result); //追加新数据
						this.mescroll.endByPage(result.length, result.totalpage)
					}else {
						this.$Toast(res.msg)
						this.mescroll.endErr()
					}
				})
			},
			delOrder(id) {
				uni.showModal({
					title: '提示',
					content: '确定删除此订单吗？',
					success: (res)=> {
						if (res.confirm) {
							uni.showLoading()
							OrderCenterApi.del_order({id}).then(res=> {
								this.$HideLoading()
								console.log('删除维权订单', res);
								this.$u.toast(res.msg, 2000)
								if(res.code == 1){
									this.mescroll.resetUpScroll() 
								}
							})
						}
					}
				})
			},
			toOrderDetail(index) {
				this.toDetail(this.goodsList[index].order_no, this.goodsList[index].id, this.goodsList[index].goods_id)
			},
			toDetail(order_no, id, goods_id) {
				uni.navigateTo({
					url: '/pages/order/mineOrderAfterDetail/mineOrderAfterDetail?info=' + JSON.stringify({order_no,id, goods_id })
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
